package com.zjy.system.controller;

import com.zjy.basic.util.AjaxResult;
import com.zjy.basic.util.PageList;
import com.zjy.system.domain.Systemdictionarytype;
import com.zjy.system.query.SystemdictionarytypeQuery;
import com.zjy.system.service.SystemdictionarytypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemdictionarytypeController {

    @Autowired
    private SystemdictionarytypeService systemdictionarytypeService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    /**
     * 查询单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarytype findById(@PathVariable("id") Long id){
        return systemdictionarytypeService.findById(id);
    }

    /**
     * 接口：分页查询
     * @param systemdictionarytypeQuery
     * @return
     */
    //post http://localhost:8080/systemdictionarytype 对象
    @PostMapping
    @ApiOperation(value = "分页查询" )
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery systemdictionarytypeQuery){
        return systemdictionarytypeService.queryPage(systemdictionarytypeQuery);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.del(id);
            return new AjaxResult(true,"删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    public AjaxResult save(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if(systemdictionarytype.getId()==null){
                systemdictionarytypeService.add(systemdictionarytype);
            }else {
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new AjaxResult(true,"操作成功");
        }catch (Exception e){
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        try {
            systemdictionarytypeService.patchDel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

}
